package com.caifu.controller.baseData;

import com.caifu.controller.AbstractController;
import com.caifu.pojo.SysUser;
import com.caifu.pojo.YlCost;
import com.caifu.service.ICostService;
import com.caifu.util.FileUpload;
import com.caifu.util.ImageFileUpload;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
* 
* 功能描述：费用管理
*
* @Author  GZ
* @Date   2020/11/9 13:45
*/
@Controller
@RequestMapping("/baseData/fee")
public class FeeController extends AbstractController {

    @Autowired
    private ICostService costService;

    /**
    * 
    * 功能描述：查询费用信息列表
    *
    * @Author  GZ
    * @Date   2020/11/9 15:28
    */
    @RequestMapping("feeList")
    public String feeList(String feeType){

        return "baseData/feeList";
    }
    /**
    * 
    * 功能描述：查询费用信息列表
    *
    * @Author  GZ
    * @Date   2020/11/9 15:33
    */
    @RequestMapping("obtainFeeData")
    @ResponseBody
    public JSONObject obtainFeeData(String feeType){
        SysUser user =getUser();
        try {
            return costService.queryCostInfoList(feeType,user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
    * 
    * 功能描述：保存费用信息
    *
    * @Author  GZ
    * @Date   2020/11/9 15:34
    */
    @RequestMapping("saveFeeInfo")
    @ResponseBody
    public JSONObject saveFeeInfo(YlCost cost, MultipartFile file){
        SysUser user =getUser();
        try {
            if(null!=file&& StringUtils.isNotBlank(file.getOriginalFilename())){
                String fileUrl = FileUpload.upload (file,"nursing");
                cost.setCostImg(fileUrl);
            }
            return costService.saveCostInfo(cost,user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
    * 
    * 功能描述：查询伙食费信息
    *
    * @Author  GZ
    * @Date   2020/11/9 20:07
    */
    @RequestMapping("queryMealFeeInfo")
    @ResponseBody
    public JSONObject queryMealFeeInfo(){
        SysUser sysUser = getUser();
        try {
            return costService.queryMealFeeInfo(sysUser);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
    * 
    * 功能描述：查询费用信息详情
    *
    * @Author  GZ
    * @Date   2020/11/10 13:57
    */
    @RequestMapping("queryFeeInfoDetail")
    @ResponseBody
    public JSONObject queryFeeInfoDetail(String costNo){
        try {
            return costService.queryFeeInfoDetail(costNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
    * 
    * 功能描述：修改费用信息
    *
    * @Author  GZ
    * @Date   2020/11/10 13:59
    */
    @RequestMapping("updateFeeInfo")
    @ResponseBody
    public JSONObject updateFeeInfo(YlCost costInfo,MultipartFile file){
        try {
            if(null!=file&& StringUtils.isNotBlank(file.getOriginalFilename())){
                String fileUrl = ImageFileUpload.imgFileUpload(file,"nursing",300);
                costInfo.setCostImg(fileUrl);
            }
            return costService.updateFeeInfo(costInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
    * 
    * 功能描述：删除费用信息
    *
    * @Author  GZ
    * @Date   2020/11/10 13:51
    */
    @RequestMapping("deleteFeeInfo")
    @ResponseBody
    public JSONObject deleteFeeInfo(String costNo){
        try {
            return costService.deleteFeeInfo(costNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
